/*
 * Copyright 2017-2025 noear.org and authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.noear.solon.data.sqlink.base.session;

import java.lang.reflect.InvocationTargetException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;

/**
 * SQL会话 (用于执行SQL语句)
 *
 * @author kiryu1223
 * @since 3.0
 */
public interface SqlSession {

    interface Function<T, R> {
        R invoke(T t) throws SQLException, NoSuchFieldException, IllegalAccessException, InvocationTargetException;
    }

    /**
     * 执行查询，并返回结果
     *
     * @param func      对ResultSet进行操作并且返回结果
     * @param sql       sql语句
     * @param sqlValues 参数
     */
    <R> R executeQuery(Function<ResultSet, R> func, String sql, Collection<SqlValue> sqlValues);

    /**
     * 执行插入，并返回影响行数
     *
     * @param sql       sql语句
     * @param sqlValues 参数
     * @param length    批量下每轮的长度
     */
    long executeInsert(String sql, Collection<SqlValue> sqlValues, int length);

    /**
     * 执行更新，并返回影响行数
     *
     * @param sql       sql语句
     * @param sqlValues 参数
     */
    long executeUpdate(String sql, Collection<SqlValue> sqlValues);

    /**
     * 执行删除，并返回影响行数
     *
     * @param sql       sql语句
     * @param sqlValues 参数
     */
    long executeDelete(String sql, Collection<SqlValue> sqlValues);
}
